package com.imodia.checkoo.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.hsq.commons.util.StringUtil;
import com.hsq.commons.util.db.PageBean;
import com.imodia.checkoo.bean.CmsCatalogueBean;
import com.imodia.checkoo.service.CmsCatalogueService;
import com.imodia.checkoo.webtag.TldParam;

@Controller
public class WebToolController {
	
	@Autowired
	private CmsCatalogueService cmsCatalogueService;

	@RequestMapping("/newsListAjax.do")
	public ModelAndView newsListAjax(HttpServletRequest request,PageBean pageParam) {

		Map<String, Object> m = new HashMap<String, Object>();

		int cataId = StringUtil.requestInt(request, "cataId");
		
		String ajaxUrl = request.getParameter("ajaxUrl");
		if(ajaxUrl==null || ajaxUrl.trim().length()<=0){
			ajaxUrl = "newsListAjax";
		}
		
		CmsCatalogueBean cmsCatalogue = cmsCatalogueService.get(cataId);
		m.put(cmsCatalogue.getEnName(), cmsCatalogue);
		
		TldParam tldParam = new TldParam();
		m.put("tldParam",tldParam);
		m.put("pageParam",pageParam);
		
		
		
		return new ModelAndView("/WEB-INF/jsp/"+ajaxUrl, m);
	}
	
	
	@RequestMapping("/newsSearchAjax.do")
	public ModelAndView newsSearchAjax(HttpServletRequest request,PageBean pageParam) {

		Map<String, Object> m = new HashMap<String, Object>();

		int cataId = StringUtil.requestInt(request, "cataId");
		
		String ajaxUrl = request.getParameter("ajaxUrl");
		if(ajaxUrl!=null && ajaxUrl.trim().length()>0){
			ajaxUrl = "newsSearchAjax";
		}
		
		CmsCatalogueBean cmsCatalogue = cmsCatalogueService.get(cataId);
		m.put(cmsCatalogue.getEnName(), cmsCatalogue);
		
		String queryWord = request.getParameter("queryWord")==null?"":request.getParameter("queryWord");
		TldParam tldParam = new TldParam();
		tldParam.setQueryWord(queryWord);
		m.put("tldParam",tldParam);

		m.put("pageParam",pageParam);
		
		return new ModelAndView("/WEB-INF/jsp/"+ajaxUrl, m);
	}
	
	@RequestMapping("/jobListAjax.do")
	public ModelAndView jobListAjax(HttpServletRequest request,PageBean pageParam) {
		Map<String, Object> m = new HashMap<String, Object>();
		int cataId = StringUtil.requestInt(request, "cataId");
		int areaId = StringUtil.requestInt(request, "areaId");
		CmsCatalogueBean cmsCatalogue = cmsCatalogueService.get(cataId);
		if(cmsCatalogue!=null){
			m.put(cmsCatalogue.getEnName(), cmsCatalogue);
		}
		
		TldParam tldParam = new TldParam();
		tldParam.setAreaId(areaId);
		m.put("tldParam",tldParam);
		m.put("pageParam",pageParam);
		
		return new ModelAndView("/WEB-INF/jsp/jobListAjax", m);
	}
	
}
